package org.chen.listener;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.chen.common.model.travel.StoreTravelOrder;
import org.chen.service.OrderTaskService;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class OrderTravelCancelRefundTaskConsumer {
    private final ObjectMapper objectMapper;

    private final OrderTaskService orderTaskService;

    public OrderTravelCancelRefundTaskConsumer(ObjectMapper objectMapper, OrderTaskService orderTaskService) {
        this.objectMapper = objectMapper;
        this.orderTaskService = orderTaskService;
    }

    @KafkaListener(topics = "order-cancel_refund-task", groupId = "order-cancel-refunding-task-group")
    public void listen(String message) {
        try {
            StoreTravelOrder order = objectMapper.readValue(message, StoreTravelOrder.class);
            orderTaskService.refundCancelApply(order);
        } catch (Exception e) {
            // 处理异常，例如记录日志
            log.error("Error processing order message", e);
        }
    }
}
